package com.baizhi.luoht.controller;/**
 * @Author:luoht
 * @Description：
 * @Date：Create in 20:46 2018/10/23
 */

import com.baizhi.luoht.entity.User;
import com.baizhi.luoht.entity.UserDTO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: SpringMVC
 * @description:
 * @author: luoht
 * @create: 2018-10-23 20:46
 **/

@Controller
@RequestMapping("/params")
public class ParamsControllerr {


    @RequestMapping("/tradition01")
    public String method1(HttpServletRequest request ){
        String username = request.getParameter("username");
        System.out.println(username+"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        return "index";
    }


    @RequestMapping("/base")
    public String method2(@RequestParam("username") String name, String password, Integer age){
        System.out.println(name+"~~~~~~~~~~~~~~~~~~"+password+"~~~~~~~~~~~~~~~~~~~~~"+age);
        return "index";
    }

    @RequestMapping("/obj")
    public String method2(User user){
        System.out.println(user);
        return "index";
    }

    @RequestMapping("/array")
    public String method3(String[] strs){
    for (String str : strs) {
        System.out.println(str);
    }
        return "index";
    }


    @RequestMapping("/list")
    public String method4(@RequestParam List<String> lists){
     for (String list : lists) {
         System.out.println(list);
     }
        return "index";
    }


    @RequestMapping("/map")
    public String method5(@RequestParam Map<String,String> maps){
        System.out.println(maps);
        for (Map.Entry<String,String> entry:maps.entrySet()){
            System.out.println(entry);
        }
        return "index";
    }

    @RequestMapping("/nested")
    public String method6(User user){
         System.out.println(user);
        return "index";
    }

    @RequestMapping("/objArray")
    public String method7(UserDTO userDTO){

        for (User user : userDTO.getUsers()) {
            System.out.println(user);
        }
        return "index";
    }


    @RequestMapping("/date")
    public String method8(@DateTimeFormat(pattern ="yyyy-MM-dd" ) Date date){

        System.out.println(date+"~~~~~~~~~~~~~~~~~~~~~~~DATE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        return "index";
    }




}
